<?php
class DBC {

    function __construct() {
        mysql_connect("tomqq.fatcowmysql.com", "mxf", "mxf") or die("Could not connect: " . mysql_error());
        mysql_select_db("lz06");
        mysql_query("SET NAMES 'utf8';");
    }

    public function fetchData($sql) {
        return $this->fetchDataNormal($sql);
    }

    private function fetchDataNormal($sql) {
        $result = mysql_query($sql);

        if ($result != false) {
            $data = array();
            $i = 0;
            while (($row = mysql_fetch_array($result, MYSQL_ASSOC)) != false) {
                $data [$i] = $row;
                $i++;
            }
            mysql_free_result($result);
            return $data;
        }
        return $result;
    }

    public function insertId($sql) {
        return $this->insertIdNormal($sql);
    }

    private function insertIdNormal($sql) {
        $result = mysql_query($sql);
        if ($result) {
            return mysql_insert_id();
        }
        return $result;
    }

    public function execute($sql) {

        return $this->executeNormal($sql);
    }

    private function executeNormal($sql) {
        return mysql_query($sql);
    }

    public function getRows($sql) {
        return $this->getRowsNormal($sql);
    }

    private function getRowsNormal($sql) {
        $result = mysql_query($sql);
        if ($result != false) {
            return mysql_num_rows($result);
        }
        return $result;
    }
}
?>
